package edu.ck.imgTest;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;


public class ViewTest extends View {
	
	private Bitmap image;
	
	private int px = 0;
	private int py = 0;
	private int vx = 10;
	private int vy = 10;
	
	public ViewTest(Context context){
		super(context);
		setBackgroundColor(Color.WHITE);
		
		Resources r = context.getResources();
		image = BitmapFactory.decodeResource(r, R.drawable.sample);
	}

		
	@Override
	protected void onDraw(Canvas canvas){
		Paint paint = new Paint();
		canvas.drawBitmap(image, px-40, py-40, paint);
		
		if(px<0 || getWidth() < px) vx = -vx;
		if(py<0 || getHeight() < py) vy = -vy;
		
		px += vx;
		py += vy;	
	}
}

